PACKAGE=psi-i18n
VERSION := $(shell rpm -q --qf '%{version}\n' --specfile $(PACKAGE).spec | head -1)
RELEASE := $(shell rpm -q --qf '%{release}\n' --specfile $(PACKAGE).spec | head -1)
ARCH := $(shell rpm -q --qf '%{arch}\n' --specfile $(PACKAGE).spec | head -1)
ARCHIVEVER := $(VERSION)

BINDIR      := /usr/bin/
RPM=$(HOME)/rpm

PRODUCT      = "PCLinuxOS 2007"
export PRODUCT

QT4DIR=/usr/lib/qt4

datadir=/usr/share

TSS := ${wildcard psi_*.ts}
QMS := ${patsubst %.ts,%.qm,${TSS}}
INSTQMS := ${patsubst %,$(prefix)$(datadir)/psi/%,${QMS}}

.PHONY: all clean installdirs install cleandist distdir localcopy tar rpm rpm-install ${INSTQMS}

all: ${QMS}

${QMS}: psi_%.qm : psi_%.ts
	$(QT4DIR)/bin/lrelease $<

installdirs:
	install -d -m 0755 $(prefix)$(datadir)/psi

${INSTQMS}: ${QMS}
	install -m 0644 $< $@

install: all installdirs ${INSTQMS}

clean:
	rm -f *.tar.bz2
	rm -f *.qm

cleandist: clean
	rm -Rf $(PACKAGE)-$(VERSION)

distdir:
	if [ ! -d $(PACKAGE)-$(VERSION) ]; then mkdir $(PACKAGE)-$(VERSION); fi

localcopy: clean distdir
	tar cp --exclude=.svn --exclude=$(PACKAGE)-$(VERSION) --exclude=*.tar.bz2 --exclude=*.tar.gz . | tar xp -C $(PACKAGE)-$(VERSION)
	
tar: cleandist localcopy
	tar cjvf $(PACKAGE)-$(ARCHIVEVER).tar.bz2 $(PACKAGE)-$(VERSION)
	rm -rf $(PACKAGE)-$(VERSION)

rpm: tar
	rpmbuild -ta $(PACKAGE)-$(ARCHIVEVER).tar.bz2

rpm-install: rpm
	rpm -Uvh --force /usr/src/rpm/RPMS/$(ARCH)/$(PACKAGE)-$(VERSION)-$(RELEASE).$(ARCH).rpm

upload:
	scp /usr/src/rpm/RPMS/$(ARCH)/$(PACKAGE)-$(VERSION)-$(RELEASE).$(ARCH).rpm dsmid@oko.clever.cz:www/pclinuxos/2007/RPMS.czech
	scp /usr/src/rpm/SRPMS/$(PACKAGE)-$(VERSION)-$(RELEASE).src.rpm dsmid@oko.clever.cz:www/pclinuxos/2007/SRPMS.czech
	ssh dsmid@oko.clever.cz www/pclinuxos/2007/regenerate
